/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ihmproject.menuoutils;

import java.io.IOException;
import org.ihmproject.treewindow.FenetreArbreTopComponent;
import org.ihmproject.voletEdition.MyNode.DeleteCookieImpl;
import org.openide.cookies.EditCookie;
import org.openide.cookies.SaveCookie;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;
import org.openide.windows.WindowManager;
import org.openide.windows.Mode;

public final class SupprimerSousArbreAction extends CookieAction {

    protected void performAction(Node[] activatedNodes) {
        DeleteCookieImpl editCookie = activatedNodes[0].getLookup().lookup(DeleteCookieImpl.class);
        try {
            editCookie.save();
            Mode mod = WindowManager.getDefault().findMode(FenetreArbreTopComponent.findInstance());
            FenetreArbreTopComponent fatc = (FenetreArbreTopComponent) mod.getSelectedTopComponent();
            if (fatc.scene.getSelectedObjects().toArray().length > 0)
            fatc.removeNode(((String)fatc.scene.getSelectedObjects().toArray()[0]));
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }

    protected int mode() {
        return CookieAction.MODE_EXACTLY_ONE;
    }

    public String getName() {
        return NbBundle.getMessage(SupprimerSousArbreAction.class, "CTL_SupprimerSousArbreAction");
    }

    protected Class[] cookieClasses() {
        return new Class[]{DeleteCookieImpl.class};
    }

    @Override
    protected String iconResource() {
        return "org/ihmproject/menuoutils/db_remove_24.png";
    }

    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;
    }

    @Override
    protected boolean asynchronous() {
        return false;
    }
}

